﻿using System;

using MongoDB.Driver;
using MongoDB.Bson;
using MongoDB.Driver.Builders;

namespace MVCBootstrap.MongoDB {

	public class Collection<TEntity> : Repository<TEntity>, IMongoCollection<TEntity> where TEntity : class {

		public Collection(IConnection connection)
			: base(connection.Collection<TEntity>()) {
		}

		public void Delete(ObjectId id) {
			this.GetCollection().Remove(Query.EQ("_id", id));
		}

		public TEntity Read(ObjectId id) {
			return this.GetCollection().FindOneAs<TEntity>(Query.EQ("_id", id));
		}

		public MongoCollection<TEntity> GetCollection() {
			return this.collection;
		}
	}
}